package com.aistar.servlet;

import com.alibaba.fastjson.JSON;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * Created by Administrator on 2019/9/11.
 */
@WebServlet(name = "GetMemberByTelnoServlet",urlPatterns = "/member/checkTelno")
public class GetMemberByTelnoServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //1.验证手机号是否可以使用
        String telnoStr = request.getParameter("telno");
        System.out.println("telnoStr:"+telnoStr);
        Long telno = Long.valueOf(telnoStr);

        PrintWriter out = response.getWriter();
        if (telno == 109434094){  //"0"表示手机号可不用   “1”可以使用
            out.print(JSON.toJSONString(0));
            System.out.println("手机号不可用");
        }else{
            //out.print(JSON.toJSONString("telno can use"));
            System.out.println("手机号可用");
            //2.发送验证码
            String code = "374854";//GetMessageCode.getCode(telnoStr);
            out.print(code);
        }
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            this.doPost(request,response);
    }
}
